﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;

/// <summary>
/// Summary description for DataProvider
/// </summary>
public class DataProvider
{
    public static OleDbConnection KetNoiDuLieu()
    {
        try
        {
            string sConnectionString = "Provider=Microsoft.JET.OleDb.4.0; Data Source = |DataDirectory|Data.mdb;";
            OleDbConnection con = new OleDbConnection(sConnectionString);
            con.Open();
            return con;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public static DataTable Laydulieu(OleDbConnection con, string sQuery)
    {
        try
        {
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(sQuery, con);
            da.Fill(dt);
            return dt;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    public static bool executeNonQuery(string sQuery, OleDbConnection con)
    {
        try
        {
            OleDbCommand cmd = new OleDbCommand(sQuery, con);
            cmd.ExecuteNonQuery();
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

    public static void Dongketnoi(OleDbConnection con)
    {
        con.Close();
    }
}